package com.mjlf.akka.simple;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;

/**
 * @ClassName ForwardDemo
 * @auther mjlf
 * @Date 2019/8/5 13:52
 * @Description forward信息重定向
 */
public class ForwardDemo {

    static class ForwardActor extends AbstractActor{
        @Override
        public Receive createReceive() {
            return receiveBuilder().matchAny(msg ->{
                System.out.println("forward : " + msg);
                getSender().forward(msg, getContext());
            }).build();
        }
    }

    static class SendorActor extends AbstractActor{
        @Override
        public Receive createReceive() {
            return receiveBuilder().matchAny(msg ->{
                System.out.println("sendor : " + msg);
            }).build();
        }
    }

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create();
        ActorRef forward = system.actorOf(Props.create(ForwardActor.class), "forward");
        ActorRef sender = system.actorOf(Props.create(SendorActor.class), "sender");

        forward.tell("haha", sender);
    }
}
